package com.yu.admin.modules.app.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.admin.common.annotation.NeedPermission;
import com.yu.admin.modules.app.service.AddressAdminService;
import com.yu.admin.modules.app.pojo.AddressAdmin;
import com.yu.common.util.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "系统：管理")
@RestController
@RequestMapping("/api-system/addressAdmin")
public class AddressAdminController {

    @Resource
    private AddressAdminService addressAdminService;

    @ApiOperation("查询全部")
    @NeedPermission("system:address:list")
    @GetMapping("/list")
    public R<List<AddressAdmin>> getAllAddressAdmins() {
        return R.ok(addressAdminService.getAllAddressAdmins());
    }

    @ApiOperation("分页查询")
    @NeedPermission("system:address:list")
    @GetMapping("/page")
    public R<Page<AddressAdmin>> getAddressAdminByPage(@RequestParam(defaultValue = "1") int pageNo,
                                                       @RequestParam(defaultValue = "10") int pageSize) {
        return R.ok(addressAdminService.getAddressAdminByPage(pageNo, pageSize));
    }

    @ApiOperation("增加")
    @NeedPermission("system:address:add")
    @PostMapping("")
    public R<Integer> add(@RequestBody AddressAdmin addressAdmin) {
        return R.ok(addressAdminService.addAddressAdmin(addressAdmin));
    }

    @ApiOperation("批量删除")
    @NeedPermission("system:address:delete")
    @DeleteMapping("/batch")
    public R<Integer> delete(@RequestBody List<Integer> idList) {
        return R.ok(addressAdminService.deleteAddressAdminBatchIds(idList));
    }

    @ApiOperation("修改")
    @NeedPermission("system:address:update")
    @PutMapping("")
    public R<Integer> update(@RequestBody AddressAdmin addressAdmin) {
        return R.ok(addressAdminService.updateAddressAdmin(addressAdmin));
    }

}
